package com.example.myapplication.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.myapplication.LoginActivity;
import com.example.myapplication.R;
import com.example.myapplication.utils.PreferenceUtlis;
import com.google.android.material.snackbar.Snackbar;


public class fragment4 extends Fragment  implements View.OnClickListener{
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fm4,container,false);
        RelativeLayout info = view.findViewById(R.id.userinfo);
        LinearLayout setting = view.findViewById(R.id.setting);
        TextView name = view.findViewById(R.id.name);

        info.setOnClickListener(this);
        setting.setOnClickListener(this);
        name.setOnClickListener(this);

        if (PreferenceUtlis.getInstance(getContext()).readLogin()){
            name.setText(PreferenceUtlis.getInstance(getContext()).readname());

        }
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.setting:
                if (PreferenceUtlis.getInstance(getContext()).readLogin()){
                    //TODO已经登录 跳转设置
                }else {
                    Snackbar.make(view,"请登录",Snackbar.LENGTH_SHORT).show();
                }
                break;
            case  R.id.userinfo:
                if (PreferenceUtlis.getInstance(getContext()).readLogin()){

                }else {
                    Intent intent = new Intent(getContext(), LoginActivity.class);
                    getContext().startActivity(intent);

                }
                break;


        }

    }
}
